<template>
  <el-container>
    <el-aside width="240px">
      <el-menu
            class="el-menu-vertical-demo"
            background-color="#ffffff"
            text-color="#606266"
            active-text-color="#409EFF"
            :default-openeds='["UserInfoManage","CourseInfoManage","TeachInfoManage"]'
      >
          <el-menu-item index="Index">
            <template slot="title">
              <i class="el-icon-s-home"></i>
              <span slot="title">首页</span>
            </template>
          </el-menu-item>
          <!--              动态菜单栏开发-->
          <el-submenu default-active="Index" v-for="menu in menuList" :index="menu.name" >
            <template slot="title">
              <i :class="menu.icon"></i>
              <span>{{menu.title}}</span>
            </template>
            <router-link :to="item.path" v-for="item in menu.children">
              <el-menu-item :index="item.name">
                <template slot="title">
                  <i :class="item.icon"></i>
                  <span slot="title">{{item.title}}</span>
                </template>
              </el-menu-item>
            </router-link>
          </el-submenu>
        </el-menu>
    </el-aside>
    <el-container>
      <el-header style="height: 55px;">
        <strong style="font-size: 20px">复旦教务服务系统</strong>
        <div class="header-avatar">
<!--              <el-avatar class="el-avatar"  size="medium" :src="userInfo.avatar"></el-avatar>-->
          <el-dropdown>
          <span class="el-dropdown-link" >
            {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :underline="false">
                <router-link to="/admin/userCenter">
                  个人中心
                </router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">
                <router-link to="/login">退出</router-link>
              </el-dropdown-item>
              <el-dropdown-item divided>设置</el-dropdown-item>
            </el-dropdown-menu>
            <router-link to="/login" style="margin-left: 8px; color: white">
              返回首页
            </router-link>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
          <div style="margin: 0 15px">
              <router-view></router-view>
          </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
      name: "Admin",
      data (){
        return {
          userInfo: {},
          menuList:[
            {
              name: 'UserInfoManage',
              title: '用户信息管理',
              icon: 'el-icon-user-solid',
              path: '',
              component: '',
              children: [
                {
                  name: 'Members',
                  title: '教师/学生信息管理',
                  icon: 'el-icon-s-custom',
                  path: '/admin/Members',
                  children: []
                },
                {
                  name: 'Colleges',
                  title: '院系/专业信息管理',
                  icon: 'el-icon-files',
                  path: '/admin/Colleges',
                  children: []
                },
                {
                  name: 'Majors',
                  title: '专业信息管理',
                  icon: 'el-icon-document',
                  path: '/admin/Majors',
                  children: []
                }
              ]
            },
            {
              name: 'CourseInfoManage',
              title: '课程信息管理',
              icon: 'el-icon-s-data',
              path: '',
              component: '',
              children: [
                {
                  name: 'Courses',
                  title: '课程维护',
                  icon: 'el-icon-s-claim',
                  path: '/admin/Courses',
                  children: []
                },
                {
                  name: 'TeaCourseCheck',
                  title: '教师课程申请审核',
                  icon: 'el-icon-s-check',
                  path: '/admin/TeaCourseCheck',
                  children: []
                },
                {
                  name: 'StuCourseCheck',
                  title: '选课申请审核',
                  icon: 'el-icon-finished',
                  path: '/admin/StuCourseCheck',
                  children: []
                }
              ]
            },
            {
              name: 'TeachInfoManage',
              title: '教务系统管理',
              icon: 'el-icon-menu',
              path: '',
              component: '',
              children: [
                {
                  name: 'ClassroomArrange',
                  title: '教室维护',
                  icon: 'el-icon-office-building',
                  path: '/admin/ClassroomArrange',
                  children: []
                },
                {
                  name: 'TimeArrange',
                  title: '教学时间维护',
                  icon: 'el-icon-time',
                  path: '/admin/TimeArrange',
                  children: []
                },
                {
                  name: 'CourseSwitch',
                  title: '选课权限开关',
                  icon: 'el-icon-open',
                  path: '/admin/CourseSwitch',
                  children: []
                }
              ]
            },
          ]
        }
      },
      //默认打开的
      openMenu:['UserInfoManage','CourseInfoManage','TeachInfoManage'] ,
      created() {
        this.getUserInfo()
      },
      methods: {
        getUserInfo() {
          this.$axios.get("/sys/userInfo").then(res => {
            this.userInfo = res.data.data;
            console.log("人员信息：",res.data.data);
          })
        },
        logout() {
          this.$axios.post("/logout").then(res => {
            console.log(res.data.data)
            //退出要删除数据
            localStorage.clear()
            sessionStorage.clear()
            this.$store.commit("resetState")
            this.$router.push("/login")
          })
        }
      }
    }
</script>

<style scoped>
  @import "Index.css";
</style>